package com.example.administrator.myapplication;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016/3/29 0029.
 */
public class MyFragmentPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> mFragments;
    private Context mContext;
    private final static int IMG_IDS[] = {R.drawable.tab_message_btn,R.drawable.tab_home_btn,
            R.drawable.tab_square_btn,R.drawable.tab_selfinfo_btn};
    private final static String[] ICON_TEXTS = {"微信","通讯录","发现","我"};
    public MyFragmentPageAdapter(FragmentManager fm,List<Fragment> fragments) {
        super(fm);
        this.mFragments = fragments;
    }
    //关联TabView用这个构造方法
    public MyFragmentPageAdapter(FragmentManager fm,List<Fragment> fragments,Context context){
        super(fm);
        this.mFragments = fragments;
        this.mContext = context;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }
    //设置每一个条目的图像跟文字
    public View getTabView(int position){
         View view =  View.inflate(mContext,R.layout.tab_view_item,null);
        ImageView imageView = (ImageView) view.findViewById(R.id.tab_img);
        TextView textView = (TextView) view.findViewById(R.id.tab_text);
        imageView.setImageResource(IMG_IDS[position]);
        textView.setText(ICON_TEXTS[position]);
        return view;
    }

}
